/**
 * 
 */
package org.softTank.BpelTranslator.Impl;

import java.util.List;

import javax.xml.namespace.QName;

import org.softTank.BcpModel.BcpVariable;
import org.softTank.BpelModel.TImport;
import org.softTank.BpelModel.TVariable;
import org.softTank.BpelModel.TVariables;
import org.softTank.BpelTranslator.ImportParser;
import org.softTank.BpelTranslator.VariableParser;

/**
 * @author Yuzone
 * 
 */
public class VariableParserImpl implements VariableParser {

	private ImportParser importParser;

	public VariableParserImpl() {
	}

	public VariableParserImpl(ImportParser value) {
		this.importParser = value;
	}

	public ImportParser getImportParser() {
		return importParser;
	}

	public void setImportParser(ImportParser importParser) {
		this.importParser = importParser;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.softTank.BpelTranslator.VariableParser#parseVariable(java.util.List,
	 * java.util.List)
	 */
	@Override
	public TVariables parseVariable(List<BcpVariable> value,
			List<TImport> imports) {
		TVariables variables = new TVariables();
		if (value == null || value.size() == 0)
			return variables;
		for (int n = 0; n < value.size(); n++) {
			BcpVariable bv = value.get(n);
			if (importParser != null) {
				importParser.saveOrUpdateImportList(bv, imports);
			}
			TVariable variable = new TVariable();
			variable.setName(bv.getName());
			if (bv.getName() == null || bv.getName() == "") {
				variable.setName("variable" + n);
			}
			variable.setMessageType(new QName(bv.getMessageType()
					.getTargetNamespace(), bv.getMessageType().getName()
					.getLocalPart()));
			variables.getVariable().add(variable);
		}
		return variables;
	}

}
